<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2018/7/12
 * Time: 19:08
 */

namespace app\admin\controller;

use app\admin\BaseController;
use think\Request;

class Image extends BaseController
{
    public function upload()
    {
        $file = Request::instance()->file('file');
        //把图片上传到指定的文件夹
        //图片上传成功后会有一些信息
        //我们要拿到里面的pathName=>就是文件上传成功后的文件路径 即 uploads\20180714\e792efa3fe46db63547e4593bd4341b5.png
        $info = $file->move('uploads');
       // halt($info);
        if($info && $info->getPathname())
        {
            $data =  [
                'status' => 1,
                'msg'    => 'ok',
                'data'   => '/'.$info->getPathname()
            ];
            echo json_encode($data);
            exit;
        }
       echo  json_encode(['status'=>0,'msg'=>'上传失败']);
    }
}